import { autoUpdater } from "electron-updater"
import log from "electron-log"
import devAppUpdate from '../../dev-app-update.yml?asset'
import { is } from '@electron-toolkit/utils'
import yaml from 'js-yaml'
import fs from 'node:fs'

autoUpdater.logger = log
autoUpdater.logger.transports.file.level = "info"

autoUpdater.requestHeaders = {
  elearch: process.arch,
};

// 防止报错no such file or directory dev-app-update.yml
if (is.dev) {
  autoUpdater.updateConfigPath = devAppUpdate
}

let yamlDoc = yaml.load(fs.readFileSync(devAppUpdate, 'utf8'));

autoUpdater.setFeedURL(yamlDoc.url);

autoUpdater.autoDownload = false

autoUpdater.disableWebInstaller = true

export default autoUpdater
